package zju.cst.seckill.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import zju.cst.seckill.domain.User;
import zju.cst.seckill.redis.RedisService;
import zju.cst.seckill.result.Result;
import zju.cst.seckill.service.UserService;

@Controller
@RequestMapping("/demo")
public class SampleMapping {

    @Autowired
    UserService userService;

    @Autowired
    RedisService redisService;

    @RequestMapping("/thymeleaf")
    public String thymeleaf(Model model){
        model.addAttribute("name","wbr");
        return "hello";
    }

    @RequestMapping("/db/Get")
    @ResponseBody
    public Result<User> dbGet(){
        User user=userService.getById(1);
        return Result.success(user);
    }

    @RequestMapping("/db/tx")
    @ResponseBody
    public Result<Boolean> dbTx(){
        userService.tx();
        return Result.success(true);
    }

    @RequestMapping("/redis/get")
    @ResponseBody
    public Result<String> redisGet(){
        Boolean i = redisService.set("key2","丙丙");
        String str = redisService.get("key2",String.class);
        return Result.success(str);
    }

}
